(define (pair a b)
    (* (power 2 a)
       (power 3 b)))

(define (power x y)
    (define (iter x y res)
        (if (= y 0) res
            (iter x (- y 1) (* res x))))
    (iter x y 1))

(define (first z)
    (if (odd? z)
        0
        (+ (first (/ z 2))
           1))) 

(define (second z)
    (if (even? z)
        (second (/ z 2))
        (second-help z)))

(define (second-help z)
    (if (= z 1)
        0
        (+ (second-help (/ z 3))
           1)))
